package com.gm.wj.controller;

import com.gm.wj.result.Result;
import com.gm.wj.result.ResultFactory;
import com.gm.wj.util.QiniuUtil;
import com.gm.wj.util.StringUtils;
import com.gm.wj.util.SysLoging;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @program: wj
 * @description: 上传文件
 * @author: Huang_shengjun
 * @create: 2020-09-16 14:04
 **/
@RestController
@CrossOrigin(origins = "*",maxAge = 3600)
public class UploadController {

    /**
     * 注：可以使用自己服务器作为图片地址，只能本地访问而已。也可以申请七牛云作为图片存储，通过网络访问图片
     * @param multipartFile
     * @return
     */

    @PostMapping("/api/admin/uploadimg")
    @SysLoging("七牛云图片上传")
    public Result uploadPicture(@RequestParam("file") MultipartFile multipartFile) {
        String key = StringUtils.generateOrderNo() + ".png";
        String url = QiniuUtil.uploadQN(multipartFile,key);
        return ResultFactory.buildSuccessResult("上传成功",url);
    }

    @PostMapping("/api/admin/uploadMp4")
    @SysLoging("七牛云视频上传")
    @CrossOrigin
    public Result uploadMp4(@RequestParam("file") MultipartFile multipartFile) {
        String key = StringUtils.generateOrderNo() + ".mp4";
        String url = QiniuUtil.uploadQN(multipartFile,key);
        return ResultFactory.buildSuccessResult("上传成功",url);
    }

    @PostMapping("/api/admin/uploadFile")
    @SysLoging("七牛云文件上传")
    @CrossOrigin
    public Result uploadFile(@RequestParam("file") MultipartFile multipartFile) {
        String url = QiniuUtil.uploadQNFile(multipartFile);
        return ResultFactory.buildSuccessResult("上传成功",url);
    }


}
